// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
//声明请求对象
const SubRequest = {
    // Sub请求的基本url
    BASE_URL : confing.DV_URL + "/subject",
    //请求Api
     /**
     * 根据ID编辑用户信息
     * @param {} subject
     * @param {*} callback  
     */
     edit(subject,callback){    
        if(subject != undefined && subject.subjectId != undefined){
            request.put(this.BASE_URL + "/update",subject,callback);
        }
    },
     /**
     * 根据id加载用户信息
     * @param {*} subjectId 用户编号
     * @param {*} callback 回调函数
     */
     get(subjectId,callback){
        if(subjectId){
            // 准备url
            let url = this.BASE_URL + "/get?subjectId=" + subjectId;
            request.get(url,callback);
        }
        // 如果没有subjectId，不做任何处理
    },
    list(page = 1,limit = 10,subject,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(subject){
            if(subject.subjectCode){
                url += "&subjectCode=" + subject.subjectCode;
            }
            if(subject.subjectName){
                url += "&subjectName=" + subject.shubjectName;
            }
            if(subject.subjectType){
                url += "&subjectType=" + subject.shubjectType;
            }
        }
        // 发送请求
        request.get(url,callbcak);
    },
     /**
     * 根据ID删除用户
     * @param {*} subjectId 
     * @param {*} callback 
     */
     delete(subjectId,callback){
        request.delete(this.BASE_URL + "/deleteById?subjectId=" + subjectId ,callback);
    },
     /**
     * 保存用户
     * @param {*} subject  用户对象
     * @param {*} callback  回调函数
     */
     save(subject,callback){
        let url = this.BASE_URL + "/save";
        request.post(url,subject,callback);
    }

}
export default SubRequest;